import request from '@/utils/request'
import type { ClientInfo, ClientQueryParams, ClientFormData, ClientListResponse } from './types'
import { AxiosPromise } from 'axios'

// 查询客户端列表
export function getClientList(query: ClientQueryParams): AxiosPromise<ClientListResponse> {
  return request({
    url: '/access/clients',
    method: 'get',
    params: query
  })
}

// 获取客户端详情
export function getClientInfo(id: string | number): AxiosPromise<ClientInfo> {
  return request({
    url: `/access/clients/${id}`,
    method: 'get'
  })
}

// 新增客户端
export function addClient(data: ClientFormData): AxiosPromise<void> {
  return request({
    url: '/access/clients',
    method: 'post',
    data
  })
}

// 修改客户端
export function updateClient(data: ClientFormData): AxiosPromise<void> {
  return request({
    url: '/access/clients',
    method: 'put',
    data
  })
}

// 删除客户端
export function deleteClient(id: string | number): AxiosPromise<void> {
  return request({
    url: `/access/clients/${id}`,
    method: 'delete'
  })
}

// 批量删除客户端
export function deleteClients(ids: (string | number)[]): AxiosPromise<void> {
  return request({
    url: '/access/clients/batch',
    method: 'delete',
    data: { ids }
  })
}

// 导出客户端列表
export function exportClientList(query: ClientQueryParams): AxiosPromise<Blob> {
  return request({
    url: '/access/clients/export',
    method: 'post',
    data: query,
    responseType: 'blob'
  })
}